home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Sapphire Collection / Software Vault (Sapphire Collection) (Digital Impact).ISO / cdr47 / pgloader.zip / PGRID.ASM < prev    next >
Assembly Source File  |  1994-10-01  |  26KB  |  600 lines

  1. ;=============================================================================;
  2. ; This is a loader for the PowerGrid. It's fairly simple, but looks pretty    ;
  3. ; decent... Because I'm such a damn nice guy, I figgered I'd release this     ;
  4. ; source to the public.                                                       ;
  5. ;                                                                             ;
  6. ; I dont expect this source to go un-ripped, so I wont even bother asking. I  ;
  7. ; also doubt someone will give us credit for ripping the code, so I'm gonna   ;
  8. ; forget that too. However, I do ask that a greet goes out to the group. Hey, ;
  9. ; dont cost ya nothin'...                                                     ;
  10. ;                                                                             ;
  11. ; Anyway, have at it. It's mostly uncommented, so if you just want to rip it  ;
  12. ; you'll have to work at it. ;>                                               ;
  13. ;                                                                             ;
  14. ; Heyya to: the Psychic Monks, Avalanche, TEI, Aardvark, Future Crew, iCE,    ;
  15. ; Admire, Occult and Mental Design. Also to Snibble, Mr. Fanatic, alpha,      ;
  16. ; Crimson Blade, Eternal Darkness, Cavalier, RetroSpec, Soul Rebel and the    ;
  17. ; rest of the IRC regulars - too damn numerous to name.                       ;
  18. ;                                                                             ;
  19. ; -Friar Tuck/iCE Coding Coordinator                                          ;
  20. ;=============================================================================;
  21.         ;-------------------------------;
  22.         ; General Mumbo-Jumbo           ;
  23.         .model tiny                     ;
  24.         .code                           ;
  25.         jmp ep                          ;
  26.         .386p                           ;
  27.         ;-------------------------------;
  28.         ; Subroutines:                  ;
  29.         ; SimplexAdlib                  ;
  30.         include adlib.asm               ;
  31.         ; Writer                        ;
  32.         include wr.asm                  ;
  33.         ; Lens                          ;
  34.         include lens.asm                ;
  35.         ;-------------------------------;
  36.         ; Timing Border                 ;
  37.         ; Used for testing system speed ;
  38. ;BORDER equ 1                           ;;
  39.         ;-------------------------------;
  40.         ; Esc Pressed?                  ;
  41. @escpressed macro                       ;
  42.         in   al,60h                     ;
  43.         cmp  al,1                       ;
  44. endm @escpressed                        ;
  45.         ;-------------------------------;
  46.         ; Sync to the video card        ;
  47. wait_vrt:                               ;
  48.         mov     dx,3dah                 ;
  49. wvr02:  in      al,dx                   ;
  50.         test    al,8                    ;
  51.         jz      wvr02                   ;
  52. wvr01:  in      al,dx                   ;
  53.         test    al,8                    ;
  54.         jnz     wvr01                   ;
  55.         ret                             ;
  56. ;---------------------------------------;
  57. ; write_pal - write our pal             ;
  58. ; CX = number of entries from zero      ;
  59. ;---------------------------------------;
  60. write_pal proc                          ;
  61.         push dx                         ;
  62.         push si                         ;
  63.         push ax                         ;
  64.         push cx                         ;
  65.         xor ax,ax                       ;
  66.         mov dx,03C8h                    ;
  67.         out dx,al                       ;
  68.         inc dx                          ;
  69.         mov si,offset pal               ;
  70. wp01:   lodsb                           ;
  71.         out dx,al                       ;
  72.         loop wp01                       ;
  73.         pop cx                          ;
  74.         pop ax                          ;
  75.         pop si                          ;
  76.         pop dx                          ;
  77.         ret                             ;
  78. write_pal endp                          ;
  79. ;---------------------------------------;
  80. ; do_XXXX - rotate color XXX            ;
  81. ; CL up, CH left.                       ;
  82. ;---------------------------------------;
  83. do_blues:                               ;
  84.         push cx                         ;
  85.         push 5                          ;
  86.         mov si,offset blue              ;
  87.         jmp dr_st                       ;
  88. do_green:                               ;
  89.         push cx                         ;
  90.         push 4                          ;
  91.         mov si,offset green             ;
  92.         jmp dr_st                       ;
  93. do_reds:                                ;
  94.         push cx                         ;
  95.         push 3                          ;
  96.         mov si,offset red               ;
  97. dr_st:  mov di,offset tmp               ;
  98.         mov bx,cx                       ;
  99.         mov cx,16                       ;
  100. drs03:  rep movsd                       ;
  101.         mov cx,bx                       ;
  102.         and cx,07h                      ;
  103.         jz dr_01                        ;
  104.         call up                         ;
  105. dr_01:  mov cl,bh                       ;
  106.         and cx,07h                      ;
  107.         jz dr_done                      ;
  108.         call left                       ;
  109. dr_done:                                ;
  110.         pop bx                          ;
  111.         mov di,bx                       ;
  112.         mov dx,387                      ;
  113.         mov si,offset tmp               ;
  114.         mov cx,64                       ;
  115. dr02:   lodsb                           ;
  116.         mov byte ptr cs:pal[bx],al      ;
  117.         add bx,3                        ;
  118.         loop dr02                       ;
  119.         pop cx                          ;
  120.         ret                             ;
  121.         ;-------------------------------;
  122.         ; Rotate up CX times            ;
  123. up proc                                 ;
  124.         mov dx,cx                       ;
  125. up_01:  mov di,offset tmp8              ;
  126.         mov si,offset tmp               ;
  127.         mov cx,64                       ;
  128.         rep movsb                       ;
  129.         mov si,offset tmp8              ;
  130.         movsd                           ;
  131.         movsd                           ;
  132.         dec dx                          ;
  133.         jnz up_01                       ;
  134.         ret                             ;
  135. up endp                                 ;
  136.         ;-------------------------------;
  137.         ; Rotate left CX times          ;
  138. left proc                               ;
  139.         mov dx,cx                       ;
  140. lf_01:  mov si,offset tmp               ;
  141.         mov di,si                       ;
  142.         dec di                          ;
  143.         cld                             ;
  144.         mov cx,16                       ;
  145.         rep movsd                       ;
  146.         mov di,offset tmp_end           ;
  147.         mov si,di                       ;
  148.         mov cx,8                        ;
  149.         sub si,cx                       ;
  150. lf_02:  mov al,byte ptr ds:[si]         ;
  151.         mov byte ptr es:[di],al         ;
  152.         sub si,8                        ;
  153.         sub di,8                        ;
  154.         loop lf_02                      ;
  155.         dec dx                          ;
  156.         jnz lf_01                       ;
  157.         cld                             ;
  158.         ret                             ;
  159. left endp                               ;
  160.         ;-------------------------------;
  161.         ; PRIMARY LOOP ROUTINE          ;
  162. move_em proc                            ;
  163. me00:   ;-------------------------------;
  164.         ; Align with the retrace        ;
  165.         call wait_vrt                   ;
  166.         ;-------------------------------;
  167.         ; Set our border (if used)      ;
  168. ifdef BORDER                            ;
  169.         mov dx,03C8h                    ;
  170.         mov al,0FFh                     ;
  171.         out dx,al                       ;
  172.         inc dx                          ;
  173.         mov al,03Fh                     ; white
  174.         out dx,al                       ;
  175.         out dx,al                       ;
  176.         out dx,al                       ;
  177. endif                                   ;
  178.         mov cx,255                      ;
  179.         call write_pal                  ;
  180.         ;-------------------------------;
  181.         ; Different color for lens      ;
  182. ifdef BORDER                            ;
  183.         mov dx,03C8h                    ;
  184.         mov ax,00FFh                    ;
  185.         out dx,ax                       ;
  186.         inc dx                          ;
  187.         xor ax,ax                       ;
  188.         out dx,al                       ;
  189.         mov al,03Fh                     ; blue
  190.         out dx,al                       ;
  191. endif                                   ;
  192.         ;-------------------------------;
  193.         ; Do the Lens                   ;
  194.         mov ax,cs:[lens_x]              ;
  195.         add ax,cs:[lens_xi]             ;
  196.         cmp ax,270                      ;
  197.         jl me03                         ;
  198.         mov cs:[lens_xi],-1             ;
  199.         jmp short me04                  ;
  200. me03:   cmp ax,0                        ;
  201.         jg me04                         ;
  202.         mov cs:[lens_xi],1              ;
  203. me04:   mov cs:[lens_x],ax              ;
  204.         mov bx,ax                       ;
  205.         mov ax,cs:[lens_y]              ;
  206.         add ax,cs:[lens_yi]             ;
  207.         cmp ax,600                      ;
  208.         jl me05                         ;
  209.         mov cs:[lens_yi],-3             ;
  210.         jmp short me06                  ;
  211. me05:   cmp ax,0                        ;
  212.         jg me06                         ;
  213.         mov cs:[lens_yi],3              ;
  214. me06:   mov cs:[lens_y],ax              ;
  215.         sar ax,2                        ;
  216.         mov cx,ax                       ;
  217.         call do_lens                    ;
  218.         ;-------------------------------;
  219.         ; Different color for letter    ;
  220. ifdef BORDER                            ;
  221.         mov dx,03C8h                    ;
  222.         mov ax,3FFFh                    ;
  223.         out dx,ax                       ;
  224.         inc dx                          ;
  225.         xor ax,ax                       ;
  226.         out dx,al                       ;
  227.         out dx,al                       ;
  228. endif                                   ;
  229.         ;-------------------------------;
  230.         ; Plot a letter                 ;
  231.         push es                         ;
  232.         mov ax,0A000h                   ;
  233.         mov es,ax                       ;
  234.         cmp cs:[pauseflag],1            ;
  235.         jne me01                        ;
  236.         call pause_wrds                 ;
  237.         jmp short me02                  ;
  238. me01:   call do_words                   ;
  239. me02:   pop es                          ;
  240.         ;-------------------------------;
  241.         ; Set border for grid           ;
  242. ifdef BORDER                            ;
  243.         mov dx,03C8h                    ;
  244.         mov ax,0FFh                     ;
  245.         out dx,ax                       ;
  246.         inc dx                          ;
  247.         mov al,03Fh                     ; green
  248.         out dx,al                       ;
  249.         xor ax,ax                       ;
  250.         out dx,al                       ;
  251. endif                                   ;
  252.         ;-------------------------------;
  253.         ; The SIN/COS pointers          ;
  254.         add cs:[b_lmove],2              ;
  255.         add cs:[b_umove],3              ;
  256.         inc dword ptr cs:[democount]    ;
  257.         ;-------------------------------;
  258.         ; Set up the Left/Up Rotations  ;
  259.         mov bx,cs:[b_lmove]             ;
  260.         and bx,03FFh                    ;
  261.         mov cl,byte ptr cs:sin256[bx]   ;
  262.         mov bx,cs:[b_umove]             ;
  263.         and bx,03FFh                    ;
  264.         mov ch,byte ptr cs:cos256[bx]   ;
  265. me07:                                   ;
  266.         ;-------------------------------;
  267.         ; Do the rotations              ;
  268.         call do_blues                   ;
  269.         call do_reds                    ;
  270.         call do_green                   ;
  271.         ;-------------------------------;
  272.         ; Set border for music          ;
  273. ifdef BORDER                            ;
  274.         mov dx,03C8h                    ;
  275.         mov ax,0FFFFh                   ;
  276.         out dx,ax                       ;
  277.         inc dx                          ;
  278.         mov al,03Fh                     ; White
  279.         out dx,al                       ;
  280.         out dx,al                       ;
  281. endif                                   ;
  282.         ;-------------------------------;
  283.         ; Do the Music                  ;
  284.         push ds                         ;
  285.         mov ax,seg ains3                ;
  286.         mov ds,ax                       ;
  287.         call a_dorow                    ;
  288.         pop ds                          ;
  289.         ;-------------------------------;
  290.         ; Turn off border, all done :)  ;
  291. ifdef BORDER                            ;
  292.         mov dx,03C8h                    ;
  293.         mov ax,0FFh                     ;
  294.         out dx,ax                       ;
  295.         inc dx                          ;
  296.         xor ax,ax                       ;
  297.         out dx,al                       ;
  298.         out dx,al                       ;
  299. endif                                   ;
  300.         ;-------------------------------;
  301.         ; Check for a keypress          ;
  302.         @escpressed                     ;
  303.         jnz me00                        ;
  304.         ret                             ;
  305. move_em endp                            ;
  306.         ;-------------------------------;
  307.         ; Draw the initial screens      ;
  308. drawscr:                                ;
  309.         pusha                           ;
  310.         push es                         ;
  311.         push ds                         ;
  312.         mov ax,[datseg]                 ;
  313.         mov ds,ax                       ;
  314.         ;-------------------------------;
  315.         ; Write the empty pal           ;
  316.         mov dx,03C8h                    ;
  317.         mov al,0                        ;
  318.         out dx,al                       ;
  319.         inc dx                          ;
  320.         mov cx,768                      ;
  321. ds00:   out dx,al                       ;
  322.         loop ds00                       ;
  323.         mov ax,0A000h                   ;
  324.         mov es,ax                       ;
  325.         ;-------------------------------;
  326.         ; Draw the rotated grid         ;
  327.         mov di,14400                    ;
  328.         mov cx,110                      ;
  329. ds01:   push cx                         ;
  330.         mov cx,320                      ;
  331. ds02:   cmp cx,2                        ;
  332.         jg  ds03                        ;
  333.         mov al,72                       ;
  334.         jmp short ds05                  ;
  335. ds03:   cmp cx,319                      ;
  336.         jl  ds04                        ;
  337.         mov al,73                       ;
  338.         jmp short ds05                  ;
  339. ds04:   mov ax,cs:[y]                   ;
  340.         sal ax,3                        ;
  341.         add ax,cs:[x]                   ;
  342.         and ax,03Fh                     ;
  343.         add ax,1                        ;
  344. ds05:   mov byte ptr es:[di],al         ;
  345.         mov byte ptr ds:[di],al         ;
  346.         inc di                          ;
  347.         inc cs:[x]                      ;
  348.         and cs:[x],07h                  ;
  349.         loop ds02                       ;
  350.         mov cs:[x],0                    ;
  351.         inc cs:[y]                      ;
  352.         and cs:[y],07h                  ;
  353.         pop cx                          ;
  354.         loop ds01                       ;
  355.         ;-------------------------------;
  356.         ; Line at top and bottom        ;
  357.         mov di,14400                    ;
  358.         mov cx,639                      ;
  359.         mov al,73                       ;
  360. ds06:   mov byte ptr es:[di],al         ;
  361.         mov byte ptr ds:[di],al         ;
  362.         inc di                          ;
  363.         loop ds06                       ;
  364.         mov di,49281                    ;
  365.         mov cx,639                      ;
  366.         mov al,72                       ;
  367. ds07:   mov byte ptr es:[di],al         ;
  368.         mov byte ptr ds:[di],al         ;
  369.         inc di                          ;
  370.         loop ds07                       ;
  371.         ;-------------------------------;
  372.         ; The POWERGRID Logo            ;
  373.         mov si,offset pgridscr2         ;
  374.         mov di,49920                    ;
  375.         mov cx,BYTE_TOT+320             ;
  376. ds08:   mov al,byte ptr cs:[si]         ;
  377.         inc si                          ;
  378.         add al,82                       ;
  379.         mov byte ptr ds:[di],al         ;
  380.         mov byte ptr es:[di],al         ;
  381.         inc di                          ;
  382.         loop ds08                       ;
  383.         mov si,offset pgridscr          ;
  384.         mov di,320                      ;
  385.         mov cx,BYTE_TOT+320             ;
  386. ds09:   mov al,byte ptr cs:[si]         ;
  387.         inc si                          ;
  388.         add al,82                       ;
  389.         mov byte ptr ds:[di],al         ;
  390.         mov byte ptr es:[di],al         ;
  391.         inc di                          ;
  392.         loop ds09                       ;
  393.         ;-------------------------------
  394.         xor di,di
  395.         mov al,74
  396.         mov cx,8
  397. d__0:   push cx
  398.         mov cx,40
  399. d__1:   mov byte ptr es:[di],al
  400.         mov byte ptr ds:[di],al
  401.         inc di
  402.         loop d__1
  403.         pop cx
  404.         inc al
  405.         loop d__0
  406.         ;-------------------------------;
  407.         ; Set up a benchmark border     ;
  408. ifdef BORDER                            ;
  409.         mov di,316                      ;
  410.         mov cx,200                      ;
  411.         mov eax,-1                      ;
  412. ds10:   mov dword ptr es:[di],eax       ;
  413.         mov dword ptr ds:[di],eax       ;
  414.         add di,320                      ;
  415.         loop ds10                       ;
  416. endif                                   ;
  417.         ;-------------------------------;
  418.         ; Set the Bitmap colors.        ;
  419.         pop ds                          ;
  420.         pop es                          ;
  421.         mov di,offset pal               ;
  422.         mov si,offset pgridpal          ;
  423.         add di,246                      ;
  424.         mov cx,COLOR_TOT*3              ;
  425. ds11:   lodsb                           ;
  426. ;        xor ah,ah                       ;
  427. ;        mov bx,ax                       ;
  428. ;        sal bx,1                        ;
  429. ;        add ax,bx                       ;
  430. ;        sar al,2                        ;
  431.         stosb                           ;
  432.         loop ds11                       ;
  433.         popa                            ;
  434.         mov cx,768                      ;
  435.         call write_pal                  ;
  436.         ret                             ;
  437.         ;-------------------------------;
  438.         ;-------------------------------;
  439.         ;-------------------------------;
  440.         ; ENTRY POINT                   ;
  441.         ; do some basic setup.          ;
  442. ep:     mov ax,cs                       ;
  443.         mov ds,ax                       ;
  444.         mov es,ax                       ;
  445.         mov ss,ax                       ;
  446.         mov sp,offset endstack          ;
  447.         ;-------------------------------;
  448.         ; Detect 386                    ;
  449.         mov ax,02000h                   ;
  450.         push ax                         ;
  451.         popf                            ;
  452.         pushf                           ;
  453.         pop ax                          ;
  454.         test ax,02000h                  ;
  455.         jz ending                       ;
  456.         ;-------------------------------;
  457.         ; Various inits                 ;
  458.         cld                             ;
  459.         @writer_init                    ;
  460.         ;-------------------------------;
  461.         ; Allocate extra screen         ;
  462.         mov ah,48h                      ;
  463.         mov bx,4000                     ;
  464.         int 21h                         ;
  465.         jc ending                       ;
  466.         mov [datseg],ax                 ;
  467.         ;-------------------------------;
  468.         push ds                         ;
  469.         mov ax,seg ains3                ;
  470.         mov ds,ax                       ;
  471.         call a_init                     ;
  472.         call a_init                     ;
  473.         call a_init                     ;
  474.         pop ds                          ;
  475.         ;-------------------------------;
  476.         ; Shut down the interrupts      ;
  477.         mov  al,01111010b               ;
  478.         out  21h,al                     ;
  479.         ;-------------------------------;
  480.         ; Set up the Video Mode         ;
  481.         mov ax,0013h                    ;
  482.         int 10h                         ;
  483.         ;-------------------------------;
  484.         ; Draw the startup screen       ;
  485.         call drawscr                    ;
  486.         ;-------------------------------;
  487.         ; Plot the Letters and the rest ;
  488.         call move_em                    ;
  489.         ;-------------------------------;
  490.         ; Reinstate the interrupts      ;
  491.         mov  al,0                       ;
  492.         out  21h,al                     ;
  493.         push ds                         ;
  494.         mov ax,seg ains3                ;
  495.         mov ds,ax                       ;
  496.         call a_init                     ;
  497.         pop ds                          ;
  498.         ;-------------------------------;
  499.         ; Release memory                ;
  500.         mov ax,[datseg]                 ;
  501.         mov es,ax                       ;
  502.         mov ah,49h                      ;
  503.         int 21h                         ;
  504.         ;-------------------------------;
  505.         ;-------------------------------;
  506.         ; Do Final ANSI Image           ;
  507. ending: mov ax,0003h                    ;
  508.         int 10h                         ;
  509.         mov ax,0B800h                   ;
  510.         mov es,ax                       ;
  511.         xor di,di                       ;
  512.         mov si,offset finalimage        ;
  513.         mov cx,1000                     ;
  514.         rep movsd                       ;
  515.         mov ax,0200h                    ;
  516.         xor bx,bx                       ;
  517.         mov dx,1600h                    ;
  518.         int 10h                         ;
  519.         mov ax,4C00h                    ;
  520.         int 21h                         ;
  521.         ;-------------------------------;
  522.         ; Data                          ;
  523.         ;-------------------------------;
  524.         ; Font                          ;
  525.         include newfont.dat             ;
  526.         ; Lens Data                     ;
  527.         include lens.dat                ;
  528.         ; Sin/Cos table                 ;
  529.         include sc256.dat               ;
  530.         ; Final ANSI screen             ;
  531.         include pg_final.dat            ;
  532.         ; Music                         ;
  533.         include ad_data.dat             ;
  534.         ; PowerGrid Bitmap              ;
  535.         include pgrid_sc.dat            ;
  536.         ;-------------------------------;
  537.         ; VARS                          ;
  538. lens_x  dw      10                      ;
  539. lens_xi dw      1                       ;
  540. lens_y  dw      40                      ;
  541. lens_yi dw      3                       ;
  542. b_umove dw      0                       ;
  543. b_lmove dw      0                       ;
  544.         ; Palettes.                     ;
  545. blue    db     30,30,30,30,30,30,30,30  ;
  546.         db     30,15,15,15,15,15,15,15  ;
  547.         db     30,15, 0, 0, 0, 0, 0,15  ;
  548.         db     30,15, 0, 0, 0, 0, 0,15  ;
  549.         db     30,15, 0, 0, 0, 0, 0,15  ;
  550.         db     30,15, 0, 0, 0, 0, 0,15  ;
  551.         db     30,15, 0, 0, 0, 0, 0,15  ;
  552.         db     30,15,15,15,15,15,15,15  ;
  553. red     db     10,10,10,10,10,10,10,10  ;
  554.         db     10, 4, 4, 4, 4, 4, 4, 4  ;
  555.         db     10, 4, 0, 0, 0, 0, 0, 4  ;
  556.         db     10, 4, 0, 0, 0, 0, 0, 4  ;
  557.         db     10, 4, 0, 0, 0, 0, 0, 4  ;
  558.         db     10, 4, 0, 0, 0, 0, 0, 4  ;
  559.         db     10, 4, 0, 0, 0, 0, 0, 4  ;
  560.         db     10, 4, 4, 4, 4, 4, 4, 4  ;
  561. green   db     10,10,10,10,10,10,10,10  ;
  562.         db     10, 4, 4, 4, 4, 4, 4, 4  ;
  563.         db     10, 4, 0, 0, 0, 0, 0, 4  ;
  564.         db     10, 4, 0, 0, 0, 0, 0, 4  ;
  565.         db     10, 4, 0, 0, 0, 0, 0, 4  ;
  566.         db     10, 4, 0, 0, 0, 0, 0, 4  ;
  567.         db     10, 4, 0, 0, 0, 0, 0, 4  ;
  568.         db     10, 4, 4, 4, 4, 4, 4, 4  ;
  569.         ;-------------------------------;
  570.         ; Palette work areas            ;
  571.         ; And other Vars                ;
  572. tmp8    db      8 dup(0)                ;
  573. tmp     db      63 dup(0)               ;
  574. tmp_end db      0                       ;
  575. pal     db      198 dup(0)              ;
  576.         ;-------------------------------;
  577.         ; Word colors                   ;
  578.         db      17h,17h,17h             ;
  579.         db      1Fh,1Fh,1Fh             ;
  580.         db      27h,27h,27h             ;
  581.         db      2Fh,2Fh,2Fh             ;
  582.         db      37h,37h,37h             ;
  583.         db      3Fh,3Fh,3Fh             ;
  584.         ;-------------------------------;
  585.         ; Border colors                 ;
  586.         db      0Fh,0Fh,1Fh             ;
  587.         db      17h,17h,2Fh             ;
  588.         ;-------------------------------;
  589.         ; Picture palettes              ;
  590.         db      549 dup(0)              ;
  591. bmove label word                        ;
  592. democount dd    0                       ;
  593. wr_offs dw      0                       ;
  594. x       dw      0                       ;
  595. y       dw      0                       ;
  596. datseg  dw      0                       ;
  597. startstack      dw 200h dup(0)          ;
  598. endstack        dw 0                    ;
  599.         end
  600.